Position BinarySearch(List L, ElementType X) {
    if (L == NULL)
        return NotFound;
    int start = 1, end = L->Last;
    int mid;
    while (start <= end) {
        mid = (start + end) / 2;
        if (X > L->Data[mid]) {
            start = mid + 1;
        }
        if (X < L->Data[mid]) {
            end = mid - 1;
        }
        if (X == L->Data[mid])
            return mid;
    }
    return NotFound;
}